// source --> https://ubixus.com/wp-content/plugins/bookly-addon-customer-cabinet/frontend/modules/customer_cabinet/resources/js/customer-cabinet.js?ver=3.8 (function ($) { 'use strict'; window.booklyCustomerCabinet = function (Options) { let $container = $('.' + Options.form_id); if (!$container.length) { return; } let $tabs = $('.bookly-js-tabs li a', $container), sections_ready = []; // Appointments section function initAppointments($container) { var $appointments_table = $('.bookly-appointments-list', $container), $reschedule_dialog = $('#bookly-customer-cabinet-reschedule-dialog', $container), $reschedule_date = $('#bookly-reschedule-date', $reschedule_dialog), $reschedule_time = $('#bookly-reschedule-time', $reschedule_dialog), $reschedule_error = $('#bookly-reschedule-error', $reschedule_dialog), $reschedule_save = $('#bookly-save', $reschedule_dialog), $cancel_dialog = $('#bookly-customer-cabinet-cancel-dialog', $container), $cancel_button = $('#bookly-yes', $cancel_dialog), appointments_columns = [], $appointmentDateFilter = $('#bookly-filter-date'), $staffFilter = $('#bookly-filter-staff'), $serviceFilter = $('#bookly-filter-service'), row; Object.keys(Options.appointment_columns).map(function(objectKey) { let column = Options.appointment_columns[objectKey]; switch (column) { case 'date': appointments_columns.push({data: 'start_date', responsivePriority: 1}); break; case 'location': appointments_columns.push({data: 'location', responsivePriority: 4}); break; case 'service': appointments_columns.push({data: 'service_title', responsivePriority: 3}); break; case 'staff': appointments_columns.push({data: 'staff_name', responsivePriority: 3, render: $.fn.dataTable.render.text()}); break; case 'status': appointments_columns.push({data: 'status', responsivePriority: 3}); break; case 'category': appointments_columns.push({data: 'category', responsivePriority: 4}); break; case 'online_meeting': appointments_columns.push({ data: 'online_meeting_provider', render: function (data, type, row, meta) { switch (data) { case 'zoom': return ' Zoom '; default: return ''; } } }); break; case 'join_online_meeting': appointments_columns.push({ data: 'online_meeting_provider', render: function (data, type, row, meta) { switch (data) { case 'zoom': return ' Zoom '; default: return ''; } } }); break; case 'price': appointments_columns.push({ data: 'price', responsivePriority: 3, render: function ( data, type, row, meta ) { if (row.payment_id !== null) { return ''; } return data; } }); break; case 'cancel': appointments_columns.push({ data : 'ca_id', render : function (data, type, row, meta) { switch (row.allow_cancel) { case 'expired' : return BooklyCustomerCabinetL10n.expired_appointment; case 'blank' : return ''; case 'allow' : return ''; case 'deny': return BooklyCustomerCabinetL10n.deny_cancel_appointment; } }, responsivePriority: 2, orderable : false }); break; case 'reschedule': appointments_columns.push({ data : 'ca_id', render : function (data, type, row, meta) { switch (row.allow_reschedule) { case 'expired' : return BooklyCustomerCabinetL10n.expired_appointment; case 'blank' : return ''; case 'allow' : return ''; case 'deny': return BooklyCustomerCabinetL10n.deny_cancel_appointment; } }, responsivePriority: 2, orderable : false }); break; default: if (column.match("^custom_field")) { appointments_columns.push({data: 'custom_fields.' + column.substring(13), render: $.fn.dataTable.render.text(), responsivePriority: 3, orderable: false}); } break; } }); // Date range filter let pickerRanges = {}; pickerRanges[BooklyCustomerCabinetL10n.dateRange.anyTime] = [moment(), moment().add(100, 'years')]; pickerRanges[BooklyCustomerCabinetL10n.dateRange.yesterday] = [moment().subtract(1, 'days'), moment().subtract(1, 'days')]; pickerRanges[BooklyCustomerCabinetL10n.dateRange.today] = [moment(), moment()]; pickerRanges[BooklyCustomerCabinetL10n.dateRange.tomorrow] = [moment().add(1, 'days'), moment().add(1, 'days')]; pickerRanges[BooklyCustomerCabinetL10n.dateRange.last_7] = [moment().subtract(7, 'days'), moment()]; pickerRanges[BooklyCustomerCabinetL10n.dateRange.last_30] = [moment().subtract(30, 'days'), moment()]; pickerRanges[BooklyCustomerCabinetL10n.dateRange.thisMonth] = [moment().startOf('month'), moment().endOf('month')]; pickerRanges[BooklyCustomerCabinetL10n.dateRange.nextMonth] = [moment().add(1, 'month').startOf('month'), moment().add(1, 'month').endOf('month')]; if (BooklyCustomerCabinetL10n.tasks.enabled) { pickerRanges[BooklyCustomerCabinetL10n.tasks.title] = [moment(), moment().add(1, 'days')]; } $appointmentDateFilter.daterangepicker( { parentEl : $appointmentDateFilter.closest('div'), startDate: moment(), endDate : moment().add(100, 'years'), ranges : pickerRanges, showDropdowns : true, linkedCalendars: false, autoUpdateInput: false, locale: $.extend({},BooklyCustomerCabinetL10n.dateRange, BooklyCustomerCabinetL10n.datePicker) }, function(start, end, label) { switch (label) { case BooklyCustomerCabinetL10n.tasks.title: $appointmentDateFilter .data('date', 'null') .find('span') .html(BooklyCustomerCabinetL10n.tasks.title); break; case BooklyCustomerCabinetL10n.dateRange.anyTime: $appointmentDateFilter .data('date', 'any') .find('span') .html(BooklyCustomerCabinetL10n.dateRange.anyTime); break; default: $appointmentDateFilter .data('date', start.format('YYYY-MM-DD') + ' - ' + end.format('YYYY-MM-DD')) .find('span') .html(start.format(BooklyCustomerCabinetL10n.dateRange.format) + ' - ' + end.format(BooklyCustomerCabinetL10n.dateRange.format)); } } ).data('date', 'any').find('span') .html(BooklyCustomerCabinetL10n.dateRange.anyTime); $appointmentDateFilter.on('apply.daterangepicker', function () { appointments_datatable.ajax.reload(); }); $staffFilter.on('change', function () { appointments_datatable.ajax.reload(); }) $serviceFilter.on('change', function () { appointments_datatable.ajax.reload(); }) $('.bookly-js-select') .val(null) .select2({ width: '100%', theme: 'bootstrap4', dropdownParent: '#bookly-tbs', allowClear: true, placeholder: '', language: { noResults: function() { return BooklyCustomerCabinetL10n.no_result_found; } }, }); /** * Init DataTables. */ var appointments_datatable = $appointments_table.DataTable({ order: [[0, 'desc']], info: false, lengthChange: false, pageLength: 10, pagingType: 'numbers', searching: false, processing: true, responsive: true, serverSide: true, ajax: { url: Options.ajaxurl, type: 'POST', data: function (d) { return $.extend({ action: 'bookly_customer_cabinet_get_appointments', appointment_columns: Options.appointment_columns, csrf_token: BooklyL10nGlobal.csrf_token, date: $appointmentDateFilter.data('date'), staff: $staffFilter.val(), service: $serviceFilter.val(), }, { filter: {} }, d); } }, columns: appointments_columns, dom: "<'row'<'col-sm-12'tr>><'row mt-3'<'col-sm-12'p>>", language: { zeroRecords: BooklyCustomerCabinetL10n.zeroRecords, processing: BooklyCustomerCabinetL10n.processing } }); $appointments_table.on('click', 'button', function () { if ($(this).closest('tr').hasClass('child')) { row = appointments_datatable.row($(this).closest('tr').prev().find('td:first-child')); } else { row = appointments_datatable.row($(this).closest('td')); } }); // Cancel appointment dialog $cancel_button.on('click', function () { var ladda = Ladda.create(this); ladda.start(); $.ajax({ url : Options.ajaxurl, type : 'POST', data : { action : 'bookly_customer_cabinet_cancel_appointment', csrf_token: BooklyL10nGlobal.csrf_token, ca_id : row.data().ca_id }, dataType: 'json', success : function (response) { ladda.stop(); if (response.success) { $cancel_dialog.booklyModal('hide'); appointments_datatable.ajax.reload(); } else { booklyAlert({error: [BooklyCustomerCabinetL10n.errors.cancel]}); } } }); }); // Reschedule appointment dialog $reschedule_date.daterangepicker({ parentEl : '#bookly-customer-cabinet-reschedule-dialog', singleDatePicker: true, showDropdowns : true, autoUpdateInput : true, minDate : moment().add(BooklyCustomerCabinetL10n.minDate, 'days'), maxDate : moment().add(BooklyCustomerCabinetL10n.maxDate, 'days'), locale : BooklyCustomerCabinetL10n.datePicker }).on('change', function () { $reschedule_save.prop('disabled', true); $reschedule_time.html(''); $reschedule_error.hide(); $.ajax({ url : Options.ajaxurl, type : 'POST', data : { action : 'bookly_customer_cabinet_get_day_schedule', csrf_token: BooklyL10nGlobal.csrf_token, ca_id : row.data().ca_id, date : moment($(this).val(), BooklyCustomerCabinetL10n.datePicker.format).format('DD-MM-YYYY') }, dataType: 'json', success : function (response) { if (response.data.length) { var time_options = response.data[0].options; $.each(time_options, function (index, option) { var $option = $('